package cn.echoedu.specifics;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.echoedu.daoconstants.TableName;
import cn.echoedu.entity.Image;
import cn.echoedu.entity.TelContacts;
import cn.echoedu.util.L;

public class SpecTelContacts extends BaseSpec{
	private final static String T="SpecTelContacts-------->";

	@Override
	public <T> PreparedStatement getPreparedInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		L.p(T+"getPreparedInsert");
		TelContacts currenttelcontacts=(TelContacts)currentPojo;
		String sql="insert into "+tableName+"values(?,?,?,?,?,?)";
		L.p(T+sql);
		PreparedStatement ps=con.prepareStatement(sql);
		ps.setInt(1, currenttelcontacts.getContactsid());
		ps.setString(2, currenttelcontacts.getTelcontactsname());
		ps.setString(3,currenttelcontacts.getTel());
		ps.setInt(4,currenttelcontacts.getImage().getImageid());
		ps.setString(5,currenttelcontacts.getType());
		ps.setInt(6,currenttelcontacts.getIshot());
		return ps;
	}

	@Override
	public <T> PreparedStatement getPreparedInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		L.p(T+"getPreparedInsertRunning");
		TelContacts currenttelcontacts=(TelContacts)currentPojo;
		String sql="insert into "+tableName+"(name,tel,imageid,type,ishot) values(?,?,?,?,?,?)";
		L.p(T+sql);
		PreparedStatement ps=con.prepareStatement(sql);
		ps.setString(1, currenttelcontacts.getTelcontactsname());
		ps.setString(2,currenttelcontacts.getTel());
		ps.setInt(3,currenttelcontacts.getImage().getImageid());
		ps.setString(4,currenttelcontacts.getType());
		ps.setInt(5,currenttelcontacts.getIshot());

		return ps;
	}

	@Override
	public Object getPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		TelContacts currenttelcontacts=new TelContacts();
		currenttelcontacts.setContactsid(rs.getInt(1));
		currenttelcontacts.setTelcontactsname(rs.getString(2));
		currenttelcontacts.setTel(rs.getString(3));
		currenttelcontacts.setImage(new Image());
		currenttelcontacts.setType(rs.getString(5));
		currenttelcontacts.setIshot(rs.getInt(6));
		return currenttelcontacts;
	}

	@Override
	public <T> PreparedStatement getPreparedUpdate(Connection con,
			TableName tableName, T oldPojo, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		TelContacts newcontacts=(TelContacts)currentPojo;
		TelContacts oldcontacts=(TelContacts)currentPojo;
		String sql="update "+tableName+" set name=?,tel=?,imageid=?,type=?,ishot=? " +
				"where contactsid=?";
		L.p(T+sql);
		PreparedStatement ps=con.prepareStatement(sql);
		ps.setString(1,newcontacts.getTelcontactsname());
		ps.setString(2,newcontacts.getTel());
		ps.setInt(3,newcontacts.getImage().getImageid());
		ps.setString(4,newcontacts.getType());
		ps.setInt(5,newcontacts.getIshot());
		ps.setInt(6,oldcontacts.getContactsid());
		return ps;
	}
	@Override
	public Object getLeftJoinPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		TelContacts telcontacts=new TelContacts();
		Image image=new Image();
		telcontacts.setContactsid(rs.getInt("contactsid"));
		telcontacts.setTelcontactsname(rs.getString("name"));
		telcontacts.setTel(rs.getString("tel"));
		telcontacts.setType(rs.getString("type"));
		telcontacts.setIshot(rs.getInt("ishot"));
		image.setImageid(rs.getInt("imageid"));
		try{
			image.setImagename(rs.getString("imagename"));
			image.setImagesrc(rs.getString("imagesrc"));
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println(T+"getLeftJoinPojo imageid:"+image.getImageid());
		System.out.println(T+"getLeftJoinPojo imagename:"+image.getImagename());
		System.out.println(T+"getLeftJoinPojo imagesrc:"+image.getImagesrc());
		telcontacts.setImage(image);
		return telcontacts;
	}

	@Override
	public Object getPojoBySql(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> String getPreparedInsertGetPrimaryKeySql(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
